package zhengguofeng.game;

import java.awt.*;
import java.awt.event.KeyEvent;


public class Plane  extends GameObject{

    boolean up,right,left,dowm;
    boolean live = true;
    public void drawSelf(Graphics g){
        if (live){
            g.drawImage(img,(int)x,(int)y,null);
            if(left&&x>10){
                x-=speed;

            }
            if(right&&x<Constant.GAME_WIDTH-35){
                x+=speed;
            }
            if(up&&y>40){
                y-=speed;
            }
            if(dowm&&y<Constant.GAME_HEIGHT-40){
                y+=speed;
            }else{

            }
        }



    }
    public Plane(Image img, double x, double y) {
        this.img=img;
        this.x=x;
        this.y=y;
        this.speed=6;
        this.width=img.getWidth(null);
        this.height=img.getHeight(null);
    }

   public void addDirection(KeyEvent e){
          switch (e.getKeyCode()){
              case KeyEvent.VK_LEFT:
              left = true;
              break;
              case KeyEvent.VK_RIGHT:
                  right = true;
                  break;
              case KeyEvent.VK_DOWN:
                  dowm = true;
                  break;
              case KeyEvent.VK_UP:
                  up = true;
                  break;
          }
   }
   //按键  改变方向
    public void minusDirection(KeyEvent e){
        switch (e.getKeyCode()){
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_DOWN:
                dowm = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
        }
    }

}
